package com.jackson.config;

/*
 * Author: JacksonCoder
 * FileName: RabbitMQConfig
 * Version: 1.0.0
 * Date: 2024/12/12
 */

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    /**
     * direct交换机名称
     */
    public static final String DIRECT_EXCHANGE = "directExchange";

    /**
     * direct交换机名称1
     */
    public static final String DIRECT_EXCHANGE1 = "directExchange1";

    /**
     * fanout交换机名称
     */
    public static final String FANOUT_EXCHANGE = "fanoutExchange";

    /**
     * direct 队列名称
     */
    public static final String DIRECT_QUEUE = "directQueue";

    /**
     * direct队列名称1
     */
    public static final String DIRECT_QUEUE1 = "directQueue1";

    /**
     * direct队列名称2
     */
    public static final String DIRECT_QUEUE2 = "directQueue2";


    /**
     * subQueue1 队列名称
     */
    public static final String SUB_QUEUE1 = "subQueue1";

    /**
     * subQueue2 队列名称
     */
    public static final String SUB_QUEUE2 = "subQueue2";


    /**
     * direct 路由key
     */
    public static final String DIRECT_ROUTING_KEY = "directRoutingKey";

    /**
     * topic队列名称1
     */
    public static final String TOPIC_QUEUE1="topicQueue1";

    /**
     * topic队列名称2
     */
    public static final String TOPIC_QUEUE2="topicQueue2";

    /**
     * TOPIC交换机名称
     */
    public static final String TOPIC_EXCHANGE="topicExchange";

    /**
     * 定义一个direct交换机
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    /**
     * 定义一个direct交换机1
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange1() {
        return new DirectExchange(DIRECT_EXCHANGE1);
    }

    /**
     * 定义一个fanout交换机
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(FANOUT_EXCHANGE);
    }

    /**
     * 定义一个direct1队列
     *
     * @return
     */
    @Bean
    public Queue directQueue1() {
        return new Queue(DIRECT_QUEUE1);
    }

    /**
     * 定义一个direct2队列
     *
     * @return
     */
    @Bean
    public Queue directQueue2() {
        return new Queue(DIRECT_QUEUE2);
    }

    /**
     * 定义一个subQueue1队列
     */
    @Bean
    public Queue subQueue1() {
        return new Queue(SUB_QUEUE1);
    }

    /**
     * 定义一个subQueue2队列
     */
    @Bean
    public Queue subQueue2() {
        return new Queue(SUB_QUEUE2);
    }

    /**
     * 定义一个direct队列
     */
    @Bean
    public Queue directQueue() {
        return new Queue(DIRECT_QUEUE);
    }


    /**
     * 定义一个队列和交换机的绑定
     */
    @Bean
    public Binding directBinding() {
        return BindingBuilder.bind(directQueue()).to(directExchange()).with(DIRECT_ROUTING_KEY);
    }

    /**
     * 定义一个队列和交换机的绑定
     */
    @Bean
    public Binding fanout1Binding() {
        return BindingBuilder.bind(subQueue1()).to(fanoutExchange());
    }

    /**
     * 定义一个队列和交换机的绑定
     */
    @Bean
    public Binding fanout1Binding2() {
        return BindingBuilder.bind(subQueue2()).to(fanoutExchange());
    }

    /**
     * 定义一个队列和交换机的绑定
     *
     * @return
     */
    @Bean
    public Binding directBinding1() {
        return BindingBuilder.bind(directQueue1()).to(directExchange1()).with("error");
    }

    /**
     * 定义一个队列和交换机的绑定
     *
     * @return
     */
    @Bean
    public Binding directBinding2() {
        return BindingBuilder.bind(directQueue2()).to(directExchange1()).with("info");
    }

    /**
     * 定义一个队列和交换机的绑定
     *
     * @return
     */
    @Bean
    public Binding directBinding3() {
        return BindingBuilder.bind(directQueue2()).to(directExchange1()).with("error");
    }

    /**
     * 定义一个队列和交换机的绑定
     *
     * @return
     */
    @Bean
    public Binding directBinding4() {
        return BindingBuilder.bind(directQueue2()).to(directExchange1()).with("warning");
    }

    /**
     * 定义一个topic队列1
     * @return
     */
    @Bean
    public Queue topicQueue1(){
        return new Queue(TOPIC_QUEUE1);
    }

    /**
     * 定义一个topic队列2
     * @return
     */
    @Bean
    public Queue topicQueue2(){
        return new Queue(TOPIC_QUEUE2);
    }

    /**
     * 定义一个topic交换机
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(TOPIC_EXCHANGE);
    }

    /**
     * 定义一个队列和交换机的绑定
     * @return
     */
    @Bean
    public Binding topicBinding1(){
        return BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("*.orange.*");
    }

    /**
     * 定义一个队列和交换机的绑定
     * @return
     */
    @Bean
    public Binding topicBinding2(){
        return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("*.*.rabbit");
    }

    /**
     * 定义一个队列和交换机的绑定
     * @return
     */
    @Bean
    public Binding topicBinding3(){
        return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("lazy.#");
    }
}
